const fs = require('fs')
const path = require('path')
const { promisify } = require('util')

const dbPath = path.join(__dirname,"../db/db.json")

const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)


exports.getDb = async () => {
    const data = await readFile(dbPath,'utf8')
    return JSON.parse(data)
}
exports.saveDb = async data => {
    let result = JSON.stringify(data,null,"  ")
    await writeFile(dbPath,result)
}